#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>

int fd;

void handler(int sig)
{
    char msg[50];
    sprintf(msg, "Handler for signal %d\n", sig);
    write(fd, msg, strlen(msg));
    sleep(2);
    signal(sig, handler); // 重新注册
}

int main()
{
    fd = open("multisig.log", O_WRONLY | O_CREAT | O_TRUNC, 0644);
    write(fd, "Multi-Signal Test Log\n", 22);

    signal(SIGINT, handler);
    signal(SIGQUIT, handler);

    while (1)
    {
        char input[100];
        write(fd, "Enter input:\n", 13);
        read(0, input, sizeof(input));
    }
    close(fd);
    return 0;
}